package Fragments;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.coolweather.lechat.R;
import com.tencent.imsdk.v2.V2TIMCallback;
import com.tencent.imsdk.v2.V2TIMManager;

import activity.login;

public class FragmentMine extends Fragment {
    private TextView username;
    private Button logout;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_mine,container,false);
    }

    private void initView() {
        username = getActivity().findViewById(R.id.username);
        logout = getActivity().findViewById(R.id.logout);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                V2TIMManager.getInstance().logout(new V2TIMCallback() {
                    @Override
                    public void onSuccess() {
                        Intent intent = new Intent(getContext(), login.class);
                        getActivity().startActivity(intent);
                        username.setText("");
                    }

                    @Override
                    public void onError(int code, String desc) {

                    }
                });
            }
        });
    }
}
